package com.wxy.demo.beanshell;

import bsh.EvalError;
import bsh.Interpreter;

import java.util.regex.Pattern;

/**
 * <p>
 * beanshell测试
 * </p>
 *
 * @author e-Xiaoyuan.Wang
 * @since 2023/1/11 17:23
 */
public class Main {
    public static void main(String[] args) throws EvalError {
        Interpreter i = new Interpreter();

        i.eval("String greeting = \"Hello, BeanShell!\"");
        String greeting = (String)i.get("greeting");

        System.out.println(greeting);

        i.eval("import java.util.regex.Pattern");
        i.eval("Pattern p = Pattern.compile(\"hello\", Pattern.CASE_INSENSITIVE)");
        Pattern p = (Pattern)i.get("p");

        System.out.println(p.matcher("hello").find());
        System.out.println(p.matcher("Hello").find());
        System.out.println(p.matcher("goodbye").find());
    }
}
